<?php

App::uses('AppController', 'Controller');

/**
 * Groups Controller
 *
 * @property Group $Group
 */
class HomeController  extends AppController {

    function beforeFilter() {
        $this->Auth->allow('index','loadData');       
        parent::beforeFilter();        
       
    }    
   
    public function index() {     	
        $this->loadModel('Region');
        $regions = $this->Region->query("SELECT ID, NAME FROM local as Region");
        $date = date('Y-m-d');
		$yesterday = date('Y-m-d',strtotime($date) - 86400);
		$YMD=explode("-",$yesterday);		
		$data = array();		
   			$sql ="SELECT * FROM  result as Res WHERE LOCAL_ID=1 AND DATE=\"$yesterday\"";
			$datas = $this->Region->query($sql);
			if(count($datas)>0){
				$data=$datas[0]['Res'];
			}
		$this->set('isYear',$YMD[0]);
		$this->set('isMonth',$YMD[1]);
		$this->set('isDay',$YMD[2]);	
		$this->set('data',$data);	
        $this->set('regions',$regions);       
        $this->render('/Fontend/Home/index');        
    }
    public function loadData() {
    	$this->layout= 'ajax';
    	$data = array();
		if($this->request->is('post')){
			$isLoca=$_REQUEST['isLoca'];			
			$isDate=$_REQUEST['isYeah']."-".$_REQUEST['isMonth']."-".$_REQUEST['isDay'];
			
			$this->loadModel('Region');
			$sql ="SELECT * FROM  result as Res WHERE LOCAL_ID=".$isLoca." AND DATE=\"$isDate\"";
			$datas = $this->Region->query($sql);
			if(count($datas)>0){
				$data=$datas[0]['Res'];
			}
		}
		
    	$this->set('data',$data);
    	$this->render('/Fontend/Home/load');   
    }
   
    
}
?>
